package org.esprit.ocm.client.ui.common;

import org.esprit.ocm.client.ui.ec2.MainAreaEC2;
import org.esprit.ocm.client.ui.one.MainAreaOne;
import org.esprit.ocm.dto.impl.AwsCredentialsDto;
import org.esprit.ocm.dto.impl.ServerDto;
import org.esprit.ocm.dto.impl.UserDto;

import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.VLayout;

public class MainPage {

	private static final int	HEADER_HEIGHT	= 85;

	private VLayout				mainLayout;
	private HLayout				northLayout;
	private HLayout				southLayout;
	private Layout				mainArea;

	public MainPage(String type,ServerDto server, AwsCredentialsDto credentials, UserDto user) {

		// main layout occupies the whole area
		mainLayout = new VLayout();
		mainLayout.setWidth100();
		mainLayout.setHeight100();

		northLayout = new HLayout();
		northLayout.setHeight(HEADER_HEIGHT);

		VLayout vLayout = new VLayout();
		vLayout.addMember(new HeaderArea(user));
		// vLayout.addMember(new ApplicationMenu());
		northLayout.addMember(vLayout);

		if (type.equals("oca")) {
			mainArea = new MainAreaOne(server, credentials, user);
			mainArea.setWidth("85%");
			RootLayoutPanel.get().clear();

		} else if (type.equals("ec2")) {
			mainArea = new MainAreaEC2(server, credentials, user);
			mainArea.setWidth("85%");
			RootLayoutPanel.get().clear();
		} else {
			SC.warn("No type server recognised");
		}

		southLayout = new HLayout();
		southLayout.setMembers(mainArea);

		mainLayout.addMember(northLayout);
		mainLayout.addMember(southLayout);

		// add the main layout container to GWT's root panel
		RootLayoutPanel.get().add(mainLayout);
	}
}
